﻿using ATHTaskList2012.Entities;
using ATHTaskList2012.Models.Data;
using NHibernate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ATHTaskList2012.Controllers
{
    public class CalendarController : Controller
    {
        private readonly IRepository<User> UserRepository;

        public CalendarController()
        {
            UserRepository = new Repository<User>();
        }

        public ActionResult Seed()
        {
            using (var session = NHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var user1 = new User
                    {

                        username = "athtasklist2012@gmail.com",
                        tasks = new List<Task>
                {
                    new Task {
                        taskname = "Zakupy",
                        start = DateTime.Now.AddDays(-1.0),
                        end = DateTime.Now.AddDays(-1.0).AddHours(2.0)
                    },
                    new Task {
                        taskname = "Nauka",
                        start = DateTime.Now,
                        end = DateTime.Now.AddHours(8.0)
                    }
                }
                    };
                    session.Save(user1);
                    transaction.Commit();
                }
            }
            return RedirectToAction("Index");
        }

        public ActionResult Index()
        {
             ISession session = NHibernateHelper.OpenSession();
             IList<User> all = session.CreateCriteria(typeof(User)).List<User>();
            return View(all);
            }

        }
    }
